<!DOCTYPE html>
<html>

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=9; IE=8; IE=7; IE=EDGE">
    <meta http-equiv="X-UA-Compatible" content="IE=EmulateIE7"/>
    <title>我的收藏</title>
    <link rel="icon" href="/assets/img/favicon.ico">

    <link rel="stylesheet" type="text/css" href="css/webbase.css"/>
    <link rel="stylesheet" type="text/css" href="css/pages-seckillOrder.css"/>
</head>

<body>
<!--页面顶部白条条，由js动态加载-->
<script type="text/javascript" src="plugins/jquery/jquery.min.js"></script>
<div class="nav-bottom"></div>
<script type="text/javascript">$(".nav-bottom").load("top.html");</script>

<script type="text/javascript" src="js/plugins/jquery/jquery.min.js"></script>
<script src="js/axios.min.js"></script>
<script src="js/common.js"></script>
<script type="text/javascript">
    $(function () {
        $("#service").hover(function () {
            $(".service").show();
        }, function () {
            $(".service").hide();
        });
        $("#shopcar").hover(function () {
            $("#shopcarlist").show();
        }, function () {
            $("#shopcarlist").hide();
        });

    })
</script>
<script type="text/javascript" src="js/plugins/jquery.easing/jquery.easing.min.js"></script>
<script type="text/javascript" src="js/plugins/sui/sui.min.js"></script>
<script type="text/javascript" src="js/plugins/jquery-placeholder/jquery.placeholder.min.js"></script>
<script type="text/javascript" src="js/widget/nav.js"></script>
</body>
<!--header-->
<div id="collects">
    <div id="account">
        <div class="py-container">
            <div class="yui3-g collect">
                <!--左侧列表-->
                <div class="yui3-u-1-6 list">

                    <div class="person-info">
                        <div class="person-photo"><img src="img/_/photo.png" alt=""></div>
                        <div class="person-account">
                            <span class="name">{{user.username}}</span>
                            <span class="safe"><a href="#" @click="logout">退出登录 </a></span>
                        </div>
                        <div class="clearfix"></div>
                    </div>
                    <div class="list-items">
                        <dl>
                            <dt><i>·</i> 订单中心</dt>
                            <dd><a href="home-index.html">我的订单</a></dd>
                            <dd><a href="home-order-pay.html">待付款</a></dd>
                            <dd><a href="home-order-send.html">待发货</a></dd>
                            <dd><a href="home-order-receive.html">待收货</a></dd>
                            <dd><a href="home-order-evaluate.html">待评价</a></dd>
                        </dl>
                        <dl>
                            <dt><i>·</i> 我的中心</dt>
                            <dd><a href="home-person-collect.html" class="list-active">我的收藏</a></dd>
                            <dd><a href="home-person-footmark.html">我的足迹</a></dd>
                        </dl>
                        <dl>
                            <dt><i>·</i> 物流消息</dt>
                        </dl>
                        <dl>
                            <dt><i>·</i> 设置</dt>
                            <dd><a href="home-setting-info.html">个人信息</a></dd>
                            <dd><a href="home-setting-address.html">地址管理</a></dd>
                            <dd><a href="home-setting-safe.html">安全管理</a></dd>
                        </dl>
                    </div>
                </div>
                <!--右侧主内容-->
                <div class="yui3-u-5-6 goods">
                    <div class="body" v-if="goods!=null">
                        <h4>收藏的商品</h4>
                        <div class="goods-list">
                            <ul class="yui3-g" id="goods-list">
                                <li class="yui3-u-1-4" v-for="(item,index) in goods.items" :key="index" >
                                    <div class="list-wrap">
                                        <div class="p-img"><img :src="item.image" alt=''></div>
                                        <div class="price"><strong>
                                            <span v-if="item.currentPrice<item.price">
                                                <div style="font-size:12px;color:red;">比加入时降:¥{{ly.formatPrice(item.price-item.currentPrice)}}</div>
                                                <span style="color:red">¥{{ly.formatPrice(item.currentPrice)}}</span>
                                            </span>
                                            <span v-if="item.currentPrice===item.price">¥{{ly.formatPrice(item.currentPrice)}}</span>
                                        </strong></div>
                                        <div class="attr"><em>{{item.title}}</em></div>
                                        <div class="cu"><em><span>促</span>满一件可参加超值换购</em></div>
                                        <div class="operate">
                                            <a href="javascript:void(0);" target="_blank"
                                               class="sui-btn btn-bordered btn-danger"
                                               @click="addIntoCarts(item.id,item.skuId)">加入购物车</a>
                                            <a href="javascript:void(0);" class="sui-btn btn-bordered">对比</a>
                                            <a href="javascript:void(0);" class="sui-btn btn-bordered">降价通知</a>
                                        </div>
                                    </div>
                                </li>
                                <li v-else></li>
                            </ul>
                        </div>

                        <!--分页-->
                        <div class="fr">
                            <div class="sui-pagination pagination-large">
                                <ul>
                                    <li :class="{prev:true,disabled:page.page === 1}">
                                        <a href="#" @click="prevPage">«上一页</a>
                                    </li>
                                    <li :class="{active:index(i)===page.page}" v-for="i in Math.min(5,goods.totalPage)"
                                        :key="i">
                                        <a href="#" @click="page.page=index(i)">{{index(i)}}</a>
                                    </li>
                                    <li class="dotted" v-show="goods.totalPage > 5"><span>...</span></li>
                                    <li :class="{next:true,disabled:page.page === goods.totalPage}">
                                        <a href="#" @click="nextPage">下一页»</a>
                                    </li>
                                </ul>
                                <div>
                                    <span>共{{goods.totalPage}}页&nbsp;</span>
                                    <span>
                                到第<input type="text" class="page-num" :value="page.page">页
                                <button class="page-confirm" onclick="alert(1)">确定</button>
                            </span>
                                </div>
                            </div>
                        </div>

                        <!--猜你喜欢-->
                        <div class="like-title yui3-u-1-1">
                            <div class="mt">
                                <span class="fl"><strong>猜你喜欢</strong></span>
                            </div>
                        </div>
                        <div class="like-list">
                            <ul class="yui3-g">
                                <li class="yui3-u-1-4">
                                    <div class="list-wrap">
                                        <div class="p-img">
                                            <img src="img/_/itemlike01.png"/>
                                        </div>
                                        <div class="attr">
                                            <em>DELL戴尔Ins 15MR-7528SS 15英寸 银色 笔记本</em>
                                        </div>
                                        <div class="price">
                                            <strong>
                                                <em>¥</em>
                                                <i>3699.00</i>
                                            </strong>
                                        </div>
                                        <div class="commit">
                                            <i class="command">已有6人评价</i>
                                        </div>
                                    </div>
                                </li>
                                <li class="yui3-u-1-4">
                                    <div class="list-wrap">
                                        <div class="p-img">
                                            <img src="img/_/itemlike02.png"/>
                                        </div>
                                        <div class="attr">
                                            <em>Apple苹果iPhone 6s/6s Plus 16G 64G 128G</em>
                                        </div>
                                        <div class="price">
                                            <strong>
                                                <em>¥</em>
                                                <i>4388.00</i>
                                            </strong>
                                        </div>
                                        <div class="commit">
                                            <i class="command">已有700人评价</i>
                                        </div>
                                    </div>
                                </li>
                                <li class="yui3-u-1-4">
                                    <div class="list-wrap">
                                        <div class="p-img">
                                            <img src="img/_/itemlike03.png"/>
                                        </div>
                                        <div class="attr">
                                            <em>DELL戴尔Ins 15MR-7528SS 15英寸 银色 笔记本</em>
                                        </div>
                                        <div class="price">
                                            <strong>
                                                <em>¥</em>
                                                <i>4088.00</i>
                                            </strong>
                                        </div>
                                        <div class="commit">
                                            <i class="command">已有700人评价</i>
                                        </div>
                                    </div>
                                </li>
                                <li class="yui3-u-1-4">
                                    <div class="list-wrap">
                                        <div class="p-img">
                                            <img src="img/_/itemlike04.png"/>
                                        </div>
                                        <div class="attr">
                                            <em>DELL戴尔Ins 15MR-7528SS 15英寸 银色 笔记本</em>
                                        </div>
                                        <div class="price">
                                            <strong>
                                                <em>¥</em>
                                                <i>4088.00</i>
                                            </strong>
                                        </div>
                                        <div class="commit">
                                            <i class="command">已有700人评价</i>
                                        </div>
                                    </div>
                                </li>

                            </ul>
                        </div>
                    </div>

                    <div class="body" v-else>
                        <!--此处当张图片-->

                        <!--猜你喜欢-->
                        <div class="like-title yui3-u-1-1">
                            <div class="mt">
                                <span class="fl"><strong>猜你喜欢</strong></span>
                            </div>
                        </div>
                        <div class="like-list">
                            <ul class="yui3-g">
                                <li class="yui3-u-1-4">
                                    <div class="list-wrap">
                                        <div class="p-img">
                                            <img src="img/_/itemlike01.png"/>
                                        </div>
                                        <div class="attr">
                                            <em>DELL戴尔Ins 15MR-7528SS 15英寸 银色 笔记本</em>
                                        </div>
                                        <div class="price">
                                            <strong>
                                                <em>¥</em>
                                                <i>3699.00</i>
                                            </strong>
                                        </div>
                                        <div class="commit">
                                            <i class="command">已有6人评价</i>
                                        </div>
                                    </div>
                                </li>
                                <li class="yui3-u-1-4">
                                    <div class="list-wrap">
                                        <div class="p-img">
                                            <img src="img/_/itemlike02.png"/>
                                        </div>
                                        <div class="attr">
                                            <em>Apple苹果iPhone 6s/6s Plus 16G 64G 128G</em>
                                        </div>
                                        <div class="price">
                                            <strong>
                                                <em>¥</em>
                                                <i>4388.00</i>
                                            </strong>
                                        </div>
                                        <div class="commit">
                                            <i class="command">已有700人评价</i>
                                        </div>
                                    </div>
                                </li>
                                <li class="yui3-u-1-4">
                                    <div class="list-wrap">
                                        <div class="p-img">
                                            <img src="img/_/itemlike03.png"/>
                                        </div>
                                        <div class="attr">
                                            <em>DELL戴尔Ins 15MR-7528SS 15英寸 银色 笔记本</em>
                                        </div>
                                        <div class="price">
                                            <strong>
                                                <em>¥</em>
                                                <i>4088.00</i>
                                            </strong>
                                        </div>
                                        <div class="commit">
                                            <i class="command">已有700人评价</i>
                                        </div>
                                    </div>
                                </li>
                                <li class="yui3-u-1-4">
                                    <div class="list-wrap">
                                        <div class="p-img">
                                            <img src="img/_/itemlike04.png"/>
                                        </div>
                                        <div class="attr">
                                            <em>DELL戴尔Ins 15MR-7528SS 15英寸 银色 笔记本</em>
                                        </div>
                                        <div class="price">
                                            <strong>
                                                <em>¥</em>
                                                <i>4088.00</i>
                                            </strong>
                                        </div>
                                        <div class="commit">
                                            <i class="command">已有700人评价</i>
                                        </div>
                                    </div>
                                </li>

                            </ul>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>
</div>
<!-- 底部栏位 -->
<!--页面底部，由js动态加载-->
<div class="clearfix footer"></div>
<script type="text/javascript">$(".footer").load("foot.html");</script>
<!--页面底部END-->
<script type="text/javascript">
    var collects = new Vue({
        el: "#collects",
        data: {
            ly,
            page: {
                page: 1,
                rows: 8
            },
            user: {},
            goods: {},
        },
        created() {
            ly.verifyUser().then(({data}) => {
                //已登录状态
                this.user = data;
                this.loadData()
            }).catch(() => {
                //未登录状态
                window.location = "/login.html?returnUrl=http://www.leyou.com/home-person-collect.html"
            })
        },
        methods: {
            loadData() {
                ly.http.get("/user/collections", {
                    params: {
                        page: this.page.page,
                        rows: this.page.rows
                    }
                }).then(({data}) => {
                    this.goods = data;
                }).catch(()=>{
                    this.goods = null;
                });
            },
            index(i) {
                if (this.page.page <= 3 || this.goods.totalPage <= 5) {
                    // 当前页小于3，则页码就是从 i 开始
                    return i;
                } else if (this.page.page <= this.goods.totalPage - 2) {
                    // 大于3，则从page-2开始，然后逐个加1
                    return this.page.page - 3 + i;
                } else {
                    return this.goods.totalPage - 5 + i;
                }
            },
            prevPage() {
                if (this.page.page > 1) {
                    this.page.page--
                }
            },
            nextPage() {
                if (this.page.page < this.goods.totalPage) {
                    this.page.page++
                }
            },
            addIntoCarts(id, skuId) {
                let item = this.goods.items.find(item => item.id === id);
                console.log(item);
                //删除收藏的商品
                ly.http.post("/user/collections/add", ly.stringify(item)).then(() => {
                    alert("添加至购物车成功");
                    this.loadData();
                }).catch(() => {
                    alert("添加至购物车失败")
                })
            },
        },
        watch: {
            page: {
                deep: true,
                handler(val) {
                    this.loadData();
                }
            },

        }
    });
</script>

</html>